#include <iostream>
using namespace std;

int w[105];

int main() {
	int n;
	cin >> n;
	for (int i=0; i<n; i++) {
		cin >> w[i];
	}
	int res = 0;
	for (int i=0; i<n-1; i++) {
		int j=0, k=0, min=0x3F3F3F3F, minj=-1, mink=-1;
		while (j+1<n) {
			while(w[j]==-1) {
				j++;
				if (j>=n) break;
			}
			k=j+1;
			if (k>=n) break;
			while(w[k]==-1) {
				k++;
				if (k>=n) break;
			}
			if (k>=n) break;
			if (w[j]+w[k]<min) {
				min=w[j]+w[k];
				minj=j;
				mink=k;
			}
			j=k;
		}
		res+=min;
		w[minj]=min;
		w[mink]=-1;
	}
	cout << res << endl;
	return 0;
}
